<template>
  <a-table :columns="columns" :data-source="data" bordered :pagination="false">
    <template slot="phoneSwitch" slot-scope="text,record">
      <a-switch v-if="record.type === '图片检测'" v-model="msgContent.imgPhoneSwitch" @click="saveMsg"/>
      <a-switch v-if="record.type === '视频检测'" v-model="msgContent.videoPhoneSwitch" @click="saveMsg"/>
      <a-switch v-if="record.type === '音频检测'" v-model="msgContent.audioPhoneSwitch" @click="saveMsg"/>
      <a-switch v-if="record.type === '图文检测'" v-model="msgContent.docPhoneSwitch" @click="saveMsg"/>
    </template>
    <template slot="vxIdSwitch" slot-scope="text,record">
      <a-switch v-if="record.type === '图片检测'" v-model="msgContent.imgVxIdSwitch" @click="saveMsg"/>
      <a-switch v-if="record.type === '视频检测'" v-model="msgContent.videoVxIdSwitch" @click="saveMsg"/>
      <a-switch v-if="record.type === '音频检测'" v-model="msgContent.audioVxIdSwitch" @click="saveMsg"/>
      <a-switch v-if="record.type === '图文检测'" v-model="msgContent.docVxIdSwitch" @click="saveMsg"/>
    </template>
  </a-table>
</template>

<script>
import {getMsgTemp, saveMsgTemp} from "../../services/verify";
const columns = [
  {
    title: '通知类型',
    dataIndex: 'type',
  },
  {
    title: '短信通知',
    dataIndex: 'phoneSwitch',
    scopedSlots: { customRender: 'phoneSwitch' },
  },
  {
    title: '微信通知',
    dataIndex: 'vxIdSwitch',
    scopedSlots: { customRender: 'vxIdSwitch' },
  }
];
export default {
  data() {
    return {
      data:[],
      columns,
      msgContent: {
        imgPhoneSwitch : false,
        imgVxIdSwitch : false,
        videoPhoneSwitch : false,
        videoVxIdSwitch : false,
        audioPhoneSwitch : false,
        audioVxIdSwitch : false,
        docPhoneSwitch : false,
        docVxIdSwitch : false,
      }
    };
  },
  methods: {
    onSmsChange(checked){
      console.log(`a-switch to ${checked}`);
      console.log(this.msgContent.imgPhoneSwitch)
    },
    onVxChange(checked){
      console.log(`a-switch to ${checked}`);
    },
    saveMsg(){
      saveMsgTemp(this.msgContent).then(res => {
        if (res.data.code === 0) {
          console.log(res.data());
        }
      })
    },getMsg(){
      getMsgTemp().then(res => {
        if (res.data.code === 0) {
          this.data = res.data.data;
          this.data.forEach(item =>{
            if (item.type === '图文检测') {
              this.msgContent.docVxIdSwitch = item.vxIdSwitch;
              this.msgContent.docPhoneSwitch = item.phoneSwitch;
            }else if (item.type === '图片检测') {
              this.msgContent.imgVxIdSwitch = item.vxIdSwitch;
              this.msgContent.imgPhoneSwitch = item.phoneSwitch;
            }else if (item.type === '视频检测') {
              this.msgContent.videoVxIdSwitch = item.vxIdSwitch;
              this.msgContent.videoPhoneSwitch = item.phoneSwitch;
            }else if (item.type === '音频检测') {
              this.msgContent.audioVxIdSwitch = item.vxIdSwitch;
              this.msgContent.audioPhoneSwitch = item.phoneSwitch;
            }
          })
        }
      })
    }
  },
  created() {
    this.getMsg();
  },
  name: "MsgCenter"
}
</script>

<style scoped>

</style>
